package com.deyun.smartairporthandset.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;


import com.deyun.smartairporthandset.R;
import com.deyun.smartairporthandset.entity.TestEntity;
import com.deyun.smartairporthandset.fragment.IdRegFragment;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TestAdapter extends BaseAdapter {

    private List<TestEntity> list = null;
    private Activity mContext;
    private LayoutInflater mInflater;

    public TestAdapter(List<TestEntity> list, Activity mContext) {
        this.list = list;
        this.mContext = mContext;
        mInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        final ViewHolder viewHolder;
        final TestEntity testEntity = list.get(position);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.lv_item_section_info, viewGroup, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.tv_username.setText(testEntity.getName());

        if (testEntity.isCheck()) {
            viewHolder.iv_select.setImageResource(R.mipmap.section_select);
        } else {
            viewHolder.iv_select.setImageResource(R.mipmap.section_no_select);
        }


        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.iv_select)
        ImageView iv_select;
        @BindView(R.id.tv_username)
        TextView tv_username;


        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
